package animator.phantom.paramedit.imagesource;

/*
    Copyright Janne Liljeblad 

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import animator.phantom.renderer.imagesource.SVGImageSource;
import animator.phantom.renderer.param.*;
import animator.phantom.renderer.*;
import animator.phantom.renderer.param.*;
import animator.phantom.paramedit.*;
import animator.phantom.paramedit.panel.ParamEditPanel;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Checkbox;
import animator.phantom.controller.GUIComponents;

public class SVGImageSourceEditPanel extends ParamEditPanel  implements ItemListener
{
	SVGImageSource svgImageSource;
	CheckBoxEditor asCanvas;
	FlipSelect flip;
	CheckBoxEditor contRender;

	public SVGImageSourceEditPanel( SVGImageSource svgImageSource )
	{
		this.svgImageSource = svgImageSource;
		initParamEditPanel( svgImageSource );

		CoordsEditComponents coords = new CoordsEditComponents( svgImageSource );
		AnimValueNumberEditor opacityEdit = new AnimValueNumberEditor( "Opacity", svgImageSource.opacity );
		IntegerComboBox blendSelect = new IntegerComboBox( svgImageSource.blendMode,
									"Blend mode",
									 svgImageSource.blendModes );
		blendSelect.setMaxComboRows( svgImageSource.blendModes.length );
	
		flip = new FlipSelect( svgImageSource.flipTrans );
		asCanvas = new CheckBoxEditor( svgImageSource.asCanvas, "Send as canvas", true );
		asCanvas.addItemListener( this );
		contRender = new CheckBoxEditor( svgImageSource.continuousRender, "Continuous render", true );
		contRender.addItemListener( this );
		CheckBoxEditor aOverB = new CheckBoxEditor( svgImageSource.useOverRule, "Alpha combine", true );

		//--- Put GUI together 
		addComponentsVector( coords.getEditComponents() );
		add( opacityEdit );
		add( new RowSeparator() );
		add( blendSelect );
		add( new RowSeparator() );
		add( flip );
		add( new RowSeparator() );
		add( contRender );
		//add( new RowSeparator() );
		//add( aOverB );
		add( new RowSeparator() );
		add( asCanvas );

		setUseScrollPane( true );

		//--- to display right values after load
		asCanvasPressed();
		continuousRenderPressed();
	}

	public void itemStateChanged(ItemEvent e)
	{
		if( e.getSource() == asCanvas )
			asCanvasPressed();
		if(  e.getSource() == contRender )
			continuousRenderPressed();
	}

	private void asCanvasPressed()
	{
		boolean newVal = svgImageSource.asCanvas.get();
		setAllEnabled( newVal == false );
		setEnabledRecursively( asCanvas, true );
		if( svgImageSource.continuousRender.get() == true )
			setEnabledRecursively( flip, false ); 
		GUIComponents.viewEditor.setLayerControlsEnabled( svgImageSource, !newVal );
		GUIComponents.viewEditor.setLayerDrawingEnabled( svgImageSource, !newVal );
	}

	private void continuousRenderPressed()
	{
		boolean newVal = svgImageSource.continuousRender.get();
		setEnabledRecursively( flip, newVal == false ); 
	}

}//end class